<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<div class="item">
  <c:set var="amount" value="${remainCoaches[dayhour]}"/>
  <c:set var="roomRecord" value="${roomRecords[dayhour] == null ? 0 : roomRecords[dayhour]}"/>
  <c:set var="commonRecord" value="${commonRecords[dayhour] == null ? 0 : commonRecords[dayhour]}"/>
  <c:set var="couldAppoint" value="${(currentSite.roomLimit.roomLimit - roomRecord > 0 && amount > 0) || (currentSite.roomLimit.commonLimit - commonRecord > 0 && amount > 0)}"/>
  <a href="#" data-hour="${hourPerfix}${hour}:00" class="${couldAppoint ? 'booking-btn' : ''}">
    <p class="time">
      ${hourPerfix}${hour}:00~${afterhourPerfix}${hour + 1}:00<br/>
      <c:if test="${currentSite.roomLimit.roomLimit > 0}">
         私人区域：${currentSite.roomLimit.roomLimit - roomRecord < amount ? 
         (currentSite.roomLimit.roomLimit - roomRecord > 0 ? currentSite.roomLimit.roomLimit - roomRecord : 0): 
         (amount > 0 ? amount : 0)}<br>
      </c:if>
      <c:if test="${currentSite.roomLimit.commonLimit > 0}">
         ${currentSite.fuxing ? '米域' : '公共区域' }：${currentSite.roomLimit.commonLimit - commonRecord < amount ? 
         (currentSite.roomLimit.commonLimit - commonRecord > 0 ? currentSite.roomLimit.commonLimit - commonRecord : 0) : 
         (amount > 0 ? amount : 0)}
      </c:if>
    </p>
    <c:set var="hourBegin" value="${hourPerfix}${hour}:00"></c:set>
     <c:choose>
       <c:when test="${not empty selectedSchedule and hourBegin eq selectedSchedule.occurHour and dayForSchedule eq selectedSchedule.occurDate}">
           <p class="tips color-blue">已选择</p>
       </c:when>
       <c:otherwise>
         <p class="tips ${couldAppoint ? 'color-green' : 'color-red'}">
           ${couldAppoint ? '可预约' : '已满'}
         </p>
       </c:otherwise>
     </c:choose>
  </a>
</div>
<c:if test="${hour != appointEndTime[0]-1 or isEndHour}">
  <div class="item">
    <c:set var="amount" value="${remainCoaches[halfhour]}"/>
    <c:set var="roomRecord" value="${roomRecords[halfhour] == null ? 0 : roomRecords[halfhour]}"/>
    <c:set var="commonRecord" value="${commonRecords[halfhour] == null ? 0 : commonRecords[halfhour]}"/>
    <c:set var="couldAppoint" value="${(currentSite.roomLimit.roomLimit - roomRecord > 0 && amount > 0) || (currentSite.roomLimit.commonLimit - commonRecord > 0 && amount > 0)}"/>
    <a href="#" data-hour="${hourPerfix}${hour}:30" class="${couldAppoint ? 'booking-btn' : ''}">
      <p class="time">
        ${hourPerfix}${hour}:30~${afterhourPerfix}${hour + 1}:30<br/>
        <c:if test="${currentSite.roomLimit.roomLimit > 0}">
           私人区域：${currentSite.roomLimit.roomLimit - roomRecord < amount ? 
           (currentSite.roomLimit.roomLimit - roomRecord > 0 ? currentSite.roomLimit.roomLimit - roomRecord : 0) : 
           (amount > 0 ? amount : 0)}<br>
        </c:if>
        <c:if test="${currentSite.roomLimit.commonLimit > 0}">
          ${currentSite.fuxing ? '米域' : '公共区域' }：${currentSite.roomLimit.commonLimit - commonRecord < amount ? 
          (currentSite.roomLimit.commonLimit - commonRecord > 0 ? currentSite.roomLimit.commonLimit - commonRecord : 0) : 
          (amount > 0 ? amount : 0)}
        </c:if>
      </p>
      <c:set var="hourBegin" value="${hourPerfix}${hour}:30"></c:set>
      <c:choose>
        <c:when test="${not empty selectedSchedule and hourBegin eq selectedSchedule.occurHour and dayForSchedule eq selectedSchedule.occurDate}">
          <p class="tips color-blue">已选择</p>
        </c:when>
        <c:otherwise>
          <p class="tips ${couldAppoint ? 'color-green' : 'color-red'}">
            ${couldAppoint ? '可预约' : '已满'}
          </p>
        </c:otherwise>
      </c:choose>
    </a>
  </div>
</c:if>
